package com.lmk.qs.jdbc;



import com.lmk.qs.utils.JDBCUtil;

import java.sql.*;
import java.util.Scanner;

/**
 *
 */
public class text06 {
    public  boolean login(String name,String pas){
        if(name==null||pas==null){
            return false;


        }
        Connection connection=null;
        Statement st=null;
        ResultSet rs=null;
        try {
             connection= JDBCUtil.getConnection();
            String sql="select *from emp where empname='"+name+"' and password= '"+pas+"'";
            System.out.println(sql);
             st=connection.createStatement();
            rs= st.executeQuery(sql);
           return rs.next();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            JDBCUtil.close(rs,st,connection);
        }
        return false;
    }
    public  boolean login2(String name,String pas){
        if(name==null||pas==null){
            return false;


        }
        Connection connection=null;
        PreparedStatement st=null;
        ResultSet rs=null;
        try {
            connection= JDBCUtil.getConnection();
            String sql="select *from emp where empname=? and password= ?";
            st=connection.prepareStatement(sql);
            st.setString(1,name);
            st.setString(2,pas);
            rs= st.executeQuery();
            return rs.next();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            JDBCUtil.close(rs,st,connection);
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入用户名");
        String name=sc.next();
        System.out.println("请输入密码");
        String paw=sc.next();
        boolean flag=new  text06().login(name,paw);
        if(flag){
            System.out.println("登陆成功");
        }else System.out.println("用户名或者密码错误");

    }
}
